<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> 报修详情</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="container">
      <el-descriptions title="报修信息" column="1" border="true">
        <el-descriptions-item label="报修家庭名">{{ repair.address }}</el-descriptions-item>
        <el-descriptions-item label="住址">{{ repair.address }}</el-descriptions-item>
        <el-descriptions-item label="报修信息">{{ repair.body }}</el-descriptions-item>
        <el-descriptions-item label="报修日期">{{ repair.date }}</el-descriptions-item>
        <el-descriptions-item label="当前进度">{{ repair.handleProgressDesc }}</el-descriptions-item>
        <el-descriptions-item label="相关图片">
          <el-row :gutter="20">
            <el-col :span="8" v-for="img in repair.repairImgList">
              <el-image :src="img.imgUrl"></el-image>
            </el-col>
          </el-row>
        </el-descriptions-item>

      </el-descriptions>
      <div v-for="(handle, index) in repair.repairHandleList">
        <el-divider></el-divider>
        <el-descriptions :title="'处理信息' + (index+1)" column="2" border="true" >
          <el-descriptions-item label="处理员工id">{{ handle.workerId }}</el-descriptions-item>
          <el-descriptions-item label="处理员工名">{{ handle.workerName }}</el-descriptions-item>
          <el-descriptions-item label="处理内容">{{ handle.body }}</el-descriptions-item>
          <el-descriptions-item label="处理时间">{{ handle.date }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <el-divider></el-divider>

      <div v-if="repair.handleProgress != 3">
        <el-descriptions title="新增处理信息" column="1" border="true" >
          <el-descriptions-item label="处理员工id">
            <el-input type="number" v-model="handle.workerId"></el-input>
          </el-descriptions-item>
          <el-descriptions-item label="处理内容">
            <el-input  v-model="handle.body"></el-input>
          </el-descriptions-item>
        </el-descriptions>
        <el-divider></el-divider>
        <el-button type="primary" @click="addHandle" >确认新增</el-button>
        <el-button type="success" @click="finishHandle" >完成报修</el-button>
      </div>


    </div>
  </div>
</template>

<script>
export default {
  name: "repair-desc",
  inject: ['reload'],
  data() {
    return {
      repair: {},
      handle: {}
    }
  },
  computed: {

  },
  methods: {
    getRepairById() {
      this.$axios.get("/repair/" + this.repair.id).then(res => {
        if (res.data.code == 200) {
          this.repair = res.data.obj;
          if (this.repair.handleProgress == 1) {
            this.repair.handleProgressDesc = "未处理";
          } else if (this.repair.handleProgress == 2) {
            this.repair.handleProgressDesc = "处理中";
          } else if (this.repair.handleProgress == 3) {
            this.repair.handleProgressDesc = "已完成";
          }
        }
      })
    },
    addHandle(){
      if (this.repair.handleProgress == 1) {
        this.$axios.patch("/repair", {handleProgress:2, id:this.repair.id}).then(res=>{
          if (res.data.code == 200) {
            this.$message.success("修改报修状态成功");
          }
        })
      }
      let data = {
        body: this.handle.body,
        repairId: this.repair.id,
        workerId: this.handle.workerId
      }
      this.$axios.post("/repair-handle", data).then(res=>{
        if (res.data.code == 200) {
          this.$message.success("添加成功");
          this.reload();
        }
      })
    },
    finishHandle(){
      this.$axios.patch("/repair", {handleProgress:3, id:this.repair.id}).then(res=>{
        if (res.data.code == 200) {
          this.$message.success("报修已完成");
          this.reload();
        }
      })
    }
  },
  created() {
    this.repair.id = this.$route.params.id;
    this.getRepairById();
  }
}
</script>

<style scoped>

</style>